package com.glsc.ngateway.common.base.enums;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.User;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 用户类别枚举类，同步com.glsc.ngateway.ldap.common.constant.UserTypeEnum
 */
@Getter
@AllArgsConstructor
public enum UserTypeEnum {
    /**
     * 存量数据暂时保留
     */
    @Deprecated
    GATEWAY("1", "内部用户"),
    OA("2", "OA用户"),
    SYS("3", "系统用户"),
    LABOR_DISPATCH("4", "外包人员"),
    ;

    private final String code;
    private final String desc;

    public static UserTypeEnum valuesOf(String code) {
        return Arrays.stream(UserTypeEnum.values()).filter(ut -> ut.getCode().equals(code)).findFirst().orElseThrow(() -> new RuntimeException("未匹配到用户类别" + code));
    }

    public boolean isSysUser() {
        return this.getCode().equals(SYS.getCode());
    }

    public static boolean isSysUser(User user) {
        return SYS.getCode().equals(user.getUserType());
    }

    public boolean isLaborDispatch() {
        return this.getCode().equals(LABOR_DISPATCH.getCode());
    }
}
